#define _init__c

#include    "includeAll.h"

void InitRegister ()
{


   
   
	TMOD = 0x11;		        //16bit timer0&timer1
	TH0 = (65536-19660)/256;	//2ms timer0 interrupt
	TL0 = (65536-19660)%256;
	//TH1 = (65536-1)/256;		//20ms timer1 interrupt
	//TL1 = (65536-1)%256;
	TH2 = (65536-614)/256;      //0.125ms==2khz timer2 interrupt
	TL2 = (65536-614)%256;
	RCP2H = TH2  ;
	RCP2L = TL2  ;
	IPH=0x20;
	IP=0x20;
	ET0 = 1;			//timer0 interrupt enable
	TR0 = 1;			//timer0 running
	//ET1 = 1;            //timer1 interrupt enable
	//TR1 = 1;            //timer1 running
	ET2 = 1;            //timer2 interrupt enable
	TR2 = 1;            //timer2 running
	EA = 1;
}



void InitIoport ()
{

	P0OE&=0x00;
	P1MODL &=0x00;
	P1MODH &=0x00;
	P2MOD &=0x00;
	P3MODL &=0x00;
	P3MODH &=0x00;
	
	P0OE |=b0001_1100;
	P3MODL|=b1010_1000;
	P1MODL|=b0000_0011;
	P1_0=1;
	
	 F_clrJDQ();
	 F_clrYX();
     F_clrFZJR();
}



void iap_read()
{
	iap_on();
	diyTempArr[0]=*(uint8_t xdata *)(0x3FC0);
	diyTempArr[1]=*(uint8_t xdata *)(0x3FC1);
	diyTempArr[2]=*(uint8_t xdata *)(0x3FC2);
	
	diyTimeArr[2]=*(uint16_t xdata *)(0x3FC3);
	diyTimeArr[1]=*(uint16_t xdata *)(0x3FC5);
	diyTimeArr[0]=*(uint16_t xdata *)(0x3FC7);
	iap_off();
}

void iap_write()
{
	iap_on();
    *(uint8_t xdata *)(0x3FC0)=diyTempArr[0];
	*(uint8_t xdata *)(0x3FC1)=diyTempArr[1];
	*(uint8_t xdata *)(0x3FC2)=diyTempArr[2];
	                      
	*(uint16_t xdata *)(0x3FC3)=diyTimeArr[2];
	*(uint16_t xdata *)(0x3FC5)=diyTimeArr[1];
	*(uint16_t xdata *)(0x3FC7)=diyTimeArr[0];
	iap_off();
}


void iap_on()
{
	EA=0;
	   SWCMD=0x65;
	IAPWE=0x47;
}

void iap_off()
{
	SWCMD=0x00;
	IAPWE=0;
	EA=1;
}